package trading.ctm.yunjing.module.information.fragment

import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.view.View
import android.widget.ScrollView
import cc.vv.baselibrary.fragment.BaseFragment
import cc.vv.baselibrary.util.LKToastUtil
import cc.vv.baselibrary.view.BTLoadMoreView
import cc.vv.baselibrary.view.banner.ImgBannerView
import cc.vv.baselibrary.view.pulltorefresh.PullToRefreshBase
import kotlinx.android.synthetic.main.view_fi_table_information.*
import trading.ctm.yunjing.R
import trading.ctm.yunjing.module.information.adapter.InformationAdapter

class InformationViewpagerFragment : BaseFragment(){

    override fun initLayoutRes(): Int {
        return R.layout.view_fi_table_information
    }

    var datas = arrayListOf("")
    var adapter: InformationAdapter? = null

    override fun initView(bundle: Bundle?) {
        super.initView(bundle)
        rv_if_information.layoutManager = LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false)
    }

    override fun initData(bundle: Bundle?) {
        super.initData(bundle)
        datas = arrayListOf("http://img15.3lian.com/2015/f1/90/d/106.jpg",
                "http://pic34.nipic.com/20131016/7487939_145711674162_2.jpg",
                "http://attach.bbs.miui.com/forum/201312/18/204803vxvoqod4hohod8dn.jpg",
                "http://pic29.nipic.com/20130520/7487939_205025481178_2.jpg")

    }

    override fun initAction(bundle: Bundle?) {
        super.initAction(bundle)

        val data = arrayListOf("")
        for(i in 0 until 50){
            data.add("fragment $i")
        }

        val view = View.inflate(context, R.layout.fragment_information_icon, null)
        val ibv_fi_information_icon = view.findViewById<ImgBannerView>(R.id.ibv_fi_information_icon)
        //广告轮播
        ibv_fi_information_icon.initWHPercentage(188, 375, -1)
        ibv_fi_information_icon.initImgData(datas) {
            imgPath, position -> LKToastUtil.showToastShort(data[position])
        }
        ibv_fi_information_icon.initIndicatorView(R.mipmap.icon_ctm_no_selector,R.mipmap.icon_ctm_selector,8,8)

        adapter = InformationAdapter(R.layout.view_home_information_item, data)
        adapter!!.setLoadMoreView(BTLoadMoreView())
        adapter!!.setOnLoadMoreListener({
            adapter!!.loadMoreComplete()
        }, rv_if_information)
        adapter!!.loadMoreEnd(true)
        adapter!!.addHeaderView(view)
        rv_if_information.adapter = adapter
        srl_if_information_view.setOnRefreshListener {

        }

        val v = View.inflate(context, R.layout.view_information_foot, null)
        adapter!!.addFooterView(v)

    }

}